package com.neusoft.ysu.npms.controller;


import com.github.pagehelper.PageInfo;
import com.neusoft.ysu.npms.pojo.*;
import com.neusoft.ysu.npms.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：刘金秋
 * @since 2024-06-18
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    IDepartmentService departmentService;

    @RequestMapping("/add")
    public Result add(@RequestBody Department department) {
//        System.out.println(department);
        departmentService.add(department);
        return Result.success();
    }
    @RequestMapping("/delete")
    public Result deleteMeasure(@RequestBody Department department) {
//        System.out.println(department);
        departmentService.deleteMeasure(department);
        return Result.success();
    }
    @RequestMapping("/update")
    public Result updateMeasure(@RequestBody Department department){
        departmentService.updateMeasure(department);
        return Result.success();
    }

    @RequestMapping("getAll")
    public Result getAll(){
        departmentService.selectAll();
        return Result.success();
    }

    @RequestMapping("findone")
    public Result findone(@RequestBody Department department){
        System.out.println(department);
        departmentService.findById(department);
        return Result.success();
    }

    @RequestMapping("list")
    public Result list(@RequestBody DepartmentInfo departmentInfo,
                         @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                         @RequestParam(value = "pageSize", required = false, defaultValue = "5") int pageSize){
        return Result.success(departmentService.getlist(departmentInfo, pageNum, pageSize));
    }

}
